//
//  DetailsViewController.m
//  HengHuaSupervision
//
//  Created by XD-XY on 3/20/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "DetailsViewController.h"
#import "XDTools.h"
#import "XDHeader.h"
#import "DetailInfoViewController.h"
#import "LabelEditViewController.h"
#import "ImageWallViewController.h"
#import "FMDatabase.h"
#import "MainViewController.h"
@interface DetailsViewController ()

@end

@implementation DetailsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [self calculateRemindBtnFrame:[XDTools sharedXDTools].waitCumitCount];
    [self calculateRemindBtnFrame:[[NSUserDefaults standardUserDefaults] valueForKey:@"waitCunitCount"]];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.titleLabel.text =[[XDTools sharedXDTools].mvc.mDictionary objectForKey:@"name"];;
    
    self.navigationController.navigationBar.backgroundColor = [UIColor blackColor];
    [self initDetailsViews];

	// Do any additional setup after loading the view.
    
}

//初始化界面的布局
-(void)initDetailsViews{

    
    tabBarView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 75, 704)];
    tabBarView.image = [[UIImage imageNamed:@"tabBar_image"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, .3, .3, 10)];
    tabBarView.userInteractionEnabled = YES;
    [self.contentView addSubview:tabBarView];
    
    UIButton *detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    detailBtn.frame = CGRectMake(0, 6, 75, 61);
    [detailBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_detail_un"] forState:UIControlStateNormal];
    [detailBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_detail_selected"] forState:UIControlStateHighlighted];
    [detailBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_detail_selected"] forState:UIControlStateDisabled];
    detailBtn.enabled =NO;
    detailBtn.tag = 101;
    [detailBtn addTarget:self action:@selector(btnChangeAction:) forControlEvents:UIControlEventTouchDown];
    [tabBarView addSubview:detailBtn];
    
    UIButton *editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    editBtn.frame = CGRectMake(0, detailBtn.frame.origin.y+detailBtn.frame.size.height+12, 75, 61);
    [editBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_edit_un"] forState:UIControlStateNormal];
    [editBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_edit_selected"] forState:UIControlStateHighlighted];
    [editBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_edit_selected"] forState:UIControlStateDisabled];
    editBtn.enabled =YES;
    editBtn.tag = 102;
    [editBtn addTarget:self action:@selector(btnChangeAction:) forControlEvents:UIControlEventTouchDown];
    [tabBarView addSubview:editBtn];
    
    UIButton *imageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    imageBtn.frame = CGRectMake(0, editBtn.frame.origin.y+editBtn.frame.size.height+12, 75, 61);
    [imageBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_image_un"] forState:UIControlStateNormal];
    [imageBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_Image_selected"] forState:UIControlStateHighlighted];
    [imageBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_Image_selected"] forState:UIControlStateDisabled];
    imageBtn.enabled =YES;
    imageBtn.tag = 103;
    [imageBtn addTarget:self action:@selector(btnChangeAction:) forControlEvents:UIControlEventTouchDown];

    [tabBarView addSubview:imageBtn];
    [self addChildControllers];
    
    
    
    
    
}
//添加三个子控制器
-(void)addChildControllers{
    wallVC = [[ImageWallViewController alloc] initWithAsserId:self.assert_id];
    wallVC.view.frame = CGRectMake(75, 0, self.contentView.frame.size.width-75, self.contentView.frame.size.height);
    wallVC.contentView.frame = CGRectMake(0, 0, wallVC.view.frame.size.width, wallVC.view.frame.size.height);
    wallVC.detailVC = self;
//    wallVC.assertId = self.assert_id;
    wallVC.contentView.backgroundColor =  RGBA(229, 229, 229);
    [self.contentView addSubview:wallVC.view];
    [self addChildViewController:wallVC];
    
    
    labelVC = [[LabelEditViewController alloc] init];
    labelVC.assertId = self.assert_id;
    labelVC.dvc = self;

//    labelVC.view.frame = CGRectMake(75, 0, self.contentView.frame.size.width-75, self.contentView.frame.size.height+20);
//    labelVC.view.backgroundColor = [UIColor redColor];
//    labelVC.contentView.frame = CGRectMake(0, 0, labelVC.view.frame.size.width, labelVC.view.frame.size.height);
//    labelVC.contentView.backgroundColor = [UIColor redColor];

    [self.contentView addSubview:labelVC.view];
    [self addChildViewController:labelVC];
    
    infoVC = [[DetailInfoViewController alloc] init];
    infoVC.assertId = self.assert_id;
    infoVC.view.frame = CGRectMake(75, 0, self.contentView.frame.size.width-75, self.contentView.frame.size.height+20);
    infoVC.contentView.frame = CGRectMake(0, 0, infoVC.view.frame.size.width, infoVC.view.frame.size.height);
    infoVC.contentView.backgroundColor = RGBA(229, 229, 229);
    [self.contentView addSubview:infoVC.view];
    [self addChildViewController:infoVC];
    
}
-(void)btnChangeAction:(UIButton *)sender{

    
    for (UIButton * button in [tabBarView subviews]){
        if ([button isKindOfClass:[UIButton class]]){
            if (button.tag == sender.tag){
                button.enabled = NO;
            }else{
                button.enabled =YES;
            }
        }
    }
    
    switch (sender.tag) {
        case 101:
            [self.contentView bringSubviewToFront:infoVC.view];
            break;
        case 102:
            [self.contentView bringSubviewToFront:labelVC.view];
            break;
        case 103:
            [self.contentView bringSubviewToFront:wallVC.view];
            break;
            
        default:
            break;
    }
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
